﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<JTable>" %>

<% using (Html.BeginForm())%>
<% { %>
<script src="/Scripts/ListPage.js" type="text/javascript"></script>

<div class="crumb-wrap">
    <div class="crumb-list">
        <i class="icon-font"></i>
        <a href="#">首页</a><span class="crumb-step">&gt;</span>
        <span class="crumb-name"><%=Model.PageTitle %></span><span class="crumb-step">&gt;</span>
        <span class="crumb-name"><%=Model.PageSubTitle %></span>
    </div>
</div>
<div class="search-wrap">
    <div class="search-content">
        <table class="search-tab" style="display: <%= Model.HasSearchBar%>">
            <tbody>
                <tr id="tr_search">
                    <%--<td width="120">选择分类:</td>
                    <td>
                        <select name="search-sort" id="">
                            <option value="">全部</option>
                            <option value="19">精品界面</option>
                            <option value="20">推荐界面</option>
                        </select>
                    </td>
                    <th width="70">关键字:</th>
                    <td>
                        <input class="common-text" placeholder="关键字" name="keywords" value="" id="Text1" type="text"></td>--%>

                    <% foreach (var AddItem in Model.SearchItems) %>
                    <%{ %>
                    <td><%= AddItem.Title%></td>
                    <td><%= AddItem.ControlHtml(false)%></td>
                    <%} %>

                    <td>
                        <input class="btn btn-primary btn2" name="sub" id="btnSearch" value="查询" type="button"></td>
                    <td>
                        <button class="btn btn-primary btn2" onclick="document.location='<%= Model.PageLink%>';return false;" type="button">
                            显示全部</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<div class="result-wrap">
    <form name="myform" id="myform" method="post">
        <div class="result-title">
            <div class="result-list">
                <%foreach (var th in Model.HeadLinkList)%>
                <%{%>

                <a href="<%= th.LinkUrl%>" name="<%= th.LinkName%>"><i class="icon-font"></i><%= th.LinkTitle%></a>
                <%if (th.CustomPost == EPostType.Page)
                  {%>
                <script type="text/javascript">
                    $(function () {
                        $("a[name='<%=th.LinkName%>']").click(function () {

                            var arry = location.href.split('?');
                            var query = "";
                            if (arry.length > 1) {
                                query = "?" + arry[1];
                            }
                            $("form").attr("action", "<%=th.PostUrl%>" + query);
                            $("form").submit();
                        });
                    })
                </script>
                <%}
                  //未实现
                  else if (th.CustomPost == EPostType.Ajax)
                  {%>
                <script type="text/javascript">

                    $(function () {

                        $("a[name='<%=th.LinkName%>']").click(function () {
                            var idList = "";
                            $("input[name='select']:checked").each(function () {
                                idList += $(this).val() + ",";
                            });

                            $.ajax({
                                type: "POST",
                                url: "<%=th.PostUrl%>",
                                data: { ids: idList <%=ReflectionHelper.GetPropertiesString(th.PostData)%> },
                                success: function (res) {
                                    if (res.split('|')[0] == "1") {
                                        alert('操作成功');
                                        window.location.href = location.href.replace("#", "");
                                    } else {
                                        alert('操作失败');
                                    }
                                }
                            });
                            //initAction(ids, "down");
                        });

                        //上架
                        //$("a[name='actionUp']").click(function () {
                        //    var ids = "";
                        //    $("input[name='select']").each(function () {
                        //        ids += $(this).val() + ",";
                        //    });
                        //    initAction(ids, "up");
                        //});
                    })
                </script>

                <% } %>
                <%} %>
                <%-- <a href="/Admin/ANews/Create"><i class="icon-font"></i>新增作品</a>
                <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>--%>
            </div>
        </div>
        <%if (Model.SubHeadLinkList.Count > 0)
          { %>
        <div class="result-title">
            <div class="result-list">
                <%foreach (var th in Model.SubHeadLinkList)%>
                <%{%>

                <a href="<%= th.LinkUrl%>" name="<%= th.LinkName%>"><i class="icon-font"></i><%= th.LinkTitle%></a>
                <%if (th.CustomPost == EPostType.Page)
                  {%>
                <script type="text/javascript">
                    $(function () {
                        $("a[name='<%=th.LinkName%>']").click(function () {

                            var arry = location.href.split('?');
                            var query = "";
                            if (arry.length > 1) {
                                query = "?" + arry[1];
                            }
                            $("form").attr("action", "<%=th.PostUrl%>" + query);
                            $("form").submit();
                        });
                    })
                </script>
                <%}
                  //未实现
                  else if (th.CustomPost == EPostType.Ajax)
                  {%>
                <script type="text/javascript">
                    $(function () {
                        $("a[name='<%=th.LinkName%>']").click(function () {
                            $.ajax({
                                url: "<%=th.PostUrl%>",
                                type: "POST",
                                data: "{\"ids\":\"" + 1 + "\"}",
                            })
                        });
                    })
                </script>

                <% } %>
                <%} %>
                <%-- <a href="/Admin/ANews/Create"><i class="icon-font"></i>新增作品</a>
                <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>--%>
            </div>
        </div>
        <%} %>
        <div class="result-content">
            <%var dics = new Dictionary<string, string>(); %>
            <%if (Model.HeadList != null)
              { %>
            <table class="result-tab" width="100%">
                <tbody>
                    <tr>
                        <th width="3%" style="text-align: center; display: <%= Model.ShowCheckBox%>">
                            <input type="checkbox" value="" name="selectAllcb">
                        </th>
                        <%foreach (var th in Model.HeadList)%>
                        <%{%>
                        <th width="<%= th.thWidth%>">
                            <%= th.thTitle%>
                        </th>
                        <%}%>
                        <th width="9%">操作
                        </th>
                    </tr>



                    <%foreach (var tr in Model.RowList)%>
                    <%{%>
                    <tr class="row<%= tr.RowIndex%>">
                        <td style="text-align: center; display: <%=Model.ShowCheckBox%>">
                            <input type="checkbox" value="<%= tr.KeyID%>" id="<%= tr.KeyID%>" name="select" />
                        </td>
                        <%foreach (var tri in tr.RowItems)%>
                        <%{%>
                        <td>
                            <%= tri.rContent%>
                        </td>
                        <%}%>
                        <td>
                            <%foreach (var trl in tr.LinkItems)%>
                            <%{%>
                            <a href="<%= trl.LinkUrl%>" id="<%= tr.KeyID %>" <%if (trl.LinkTarget != Target._none)
                                                                               {%>
                                target="<%=trl.LinkTarget.ToString() %>" <%} %> class="edit" name="<%= trl.LinkName%>">
                                <%= trl.LinkTitle%></a>

                            <%
                                  if (trl.CustomPost == EPostType.Page
                                      && trl.LinkName != null
                                      && !dics.ContainsKey(trl.LinkName))
                                  {
                                      dics.Add(trl.LinkName, trl.PostUrl);
                                  }   
                            %>
                            <%}%>
                        </td>
                    </tr>
                    <%}%>
                </tbody>
            </table>
            <div class="list-page">
                <%if (Model.jPager != null && Model.jPager.RecordCount > Model.jPager.PageSize)
                  {
                      Html.RenderPartial("Pager");
                  } %>
            </div>
            <%} %>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        <%foreach (var item in dics.Keys)
          {%>
        $("a[name='<%=item%>']").click(function () {
            var checkId = $(this).attr("id");
            $("#" + checkId).attr("checked", true);
            $("form").attr("action", "<%=dics[item]%>");
            $("form").submit();
        });
        <%}%>

    })
</script>
<script>
    $(function () {
        $("a[name='dels']").click(function () {
            if (!confirm("确定删除？")) {
                return false;
            }
            if ($("input[name='select']:checked").length <= 0) {
                alert("请至少勾选其中一项进行删除操作。");
                return false;
            }
            $("form").submit();
            return false;
        })
        $("a[name='del']").click(function () {
            if (!confirm("确定删除？")) {
                return false;
            }
            var checkId = $(this).attr("id");
            $("#" + checkId).attr("checked", true);
            $("form").submit();
            return false;
        })


        $("#btnSearch").click(function () {
            //获取所有input元素，包括select；过滤button元素
            var inpObjs = $(this).parent("td").parent("tr").find("input[type='text']");
            var paras = "";
            //checkbox特殊处理
            var ckbParas = "";
            var ckb = $(this).parent("tr").find("input[type='checkbox']:checked");
            if (ckb.length > 0) {
                var name = ckb.attr("name");
                var val = "";
                for (var i = 0; i < ckb.length; i++) {
                    val += $(ckb[i]).val();
                    if (i != ckb.length - 1) {
                        val += ",";
                    }
                }
                ckbParas = "&" + name + "=" + val;
            }

            //下拉框特殊处理
            var selectParas = "";
            var select = $(this).parent("td").parent("tr").find("select");
            for (i = 0; i < select.length; i++) {
                var obName = $(select[i]).attr("name");
                if (obName != "") {
                    if (selectParas != "") {
                        selectParas += "&";
                    }
                    selectParas += obName + "=" + escape($("[name=" + obName + "] option:selected").val());
                }

            }
            if (selectParas != "") {
                selectParas = "&" + selectParas;
            }
            //alert(selectParas);
            for (i = 0; i < inpObjs.length; i++) {
                var obName = $(inpObjs[i]).attr("name");
                if (obName != "") {
                    if (paras != "") {
                        paras += "&";
                    }
                    paras += obName + "=" + escape($("[name=" + obName + "]").val());
                }

            }

            var p = '<%=Request["p"]%>';

            var pn = window.location.pathname;
            if (p != "" && p != "null") {
                pn += "?p=" + p;
                location.href = pn + "&" + paras + ckbParas + selectParas;
            } else {
                location.href = pn + "?" + paras + ckbParas + selectParas;
            }
        });

        $(document).keydown(function (e) {
            if (e.keyCode == 13) {
                //Enter
                $("#btnSearch").click();
            }
        });

    })
</script>
<% }%>
